home *** CD-ROM | disk | FTP | other *** search
- Perl -Sx "{0}" {"Parameters"}; Exit 0
- #!perl
-
- @PP = (0);
-
- $PP{"DEBUGGING"} = 1;
- $PP{"macintosh"} = 0;
- $PP{"MSMAC"} = 0;
- $PP{"STDMAC"} = 0;
- $suppress = 0;
-
- while (<>) {
- if (/^#if(n?)def\s+(\w+)/) {
- if ($suppress) {
- unshift(@PP, 1);
- next;
- }
- if ($1 ne "n") {
- if (!defined($PP{$2})) {
- $suppress = 1;
- unshift(@PP, 1);
- } elsif ($PP{$2}) {
- print;
- unshift(@PP, -1);
- } else {
- unshift(@PP, 0);
- }
- } else {
- if (defined($PP{$2}) && !$PP{$2}) {
- $suppress = 1;
- unshift(@PP, 1);
- } elsif ($PP{$2}) {
- print;
- unshift(@PP, -1);
- } else {
- unshift(@PP, 0);
- }
- }
- } elsif (/^#if/) {
- $suppress = 1;
- unshift(@PP, 1);
- } elsif (/^#else/) {
- next if $suppress;
- if (!$PP[0]) {
- $suppress = 1;
- $PP[0] = 1;
- } elsif ($PP[0]==1) {
- $suppress = 0;
- $PP[0] = 0;
- } else {
- print;
- }
- } elsif (/^#endif/) {
- print if ($PP[0]==-1);
- shift @PP;
- $suppress = ($PP[0] == 1);
- }
- next if ($suppress);
- s/MP_//g;
- if (/^EXT\s+(.*\W)(\w+);/) {
- ($type,$var) = ($1,$2);
- if ($type =~ /\*\s*$/) {
- print "\t$var = NULL;\n";
- } else {
- $type =~ /^(.*\S)\s*$/;
- print "\tmemset(&$var, 0, sizeof($1));\n";
- }
- } elsif (/^EXT\s+(.*\W)(\w+)\s*\[([^\]]+)\];/) {
- ($type,$var,$idx) = ($1,$2,$3);
- $type =~ /^(.*\S)\s*$/;
- print "\tmemset(&$var, 0, sizeof($1)*$idx);\n";
- } elsif (/^EXT.*\{/) {
- while (<>) {
- last if (/\}/);
- }
- ($var) = ($_ =~ /(\w+)/);
- print "\t$var = NULL;\n";
- } elsif (/^EXT.*\W(\w+)\s+INIT\((.+)\)\s*;/) {
- print "\t$1 = $2;\n";
- }
- }
-